Skip to content

fix(Comments): a selected or highlighted thread shows its focus ring - #14156

Open
cixzhang wants to merge 2 commits into
mainfrom
lane2/comments-focus-ring
Open

cixzhang wants to merge 2 commits into
mainfrom
lane2/comments-focus-ring

Conversation

@cixzhang

@cixzhang cixzhang commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Cherry-picked from #13736 by @ernestt, who wrote this fix; the commit credits @ernestt with a Co-authored-by line. This team pull request carries it onto current main.

User impact

A keyboard user who tabs to a Comments thread that is selected (open) or highlighted by the host sees no focus indicator. That is the thread they are working in, so they lose track of where focus is. Unselected threads show the ring.

Problem and solution fit

  1. Why is there no ring? A thread's hidden toggle draws its focus ring on the thread surface. On a selected or highlighted thread, the forced-colors selection outline came after the ring in the style list. Outside forced colors, that style sets the outline to none, so it overrode the ring.
  2. Why does it harm the task? Focus visibility (WCAG 2.4.7) fails on the state a keyboard user is most likely to be in: the open thread.
  3. Why does it matter? The panel's keyboard model depends on the thread toggle (Enter or Space opens and closes the thread). A user who cannot see which toggle has focus cannot use it.

The ring now comes last in the style list. Forced colors still draw the selection outline on an unfocused selected thread, and the ring on a focused one.

Expected behavior and authority

  • The Comments docs (Accessibility, "Thread toggle"): "The whole surface takes the system focus ring while the toggle has focus."
  • architecture:interaction-modality: keyboard focus uses the shared focus-visible treatment.
  • Component audit rubric BLOCK A15 (graduation issue list): the focus ring is unset on a selected or highlighted thread. It was confirmed open on main in Chromium before this change: outline-style: none on a selected, focused thread.

Smallest restoration

The style order in CommentRow changes so surfaceFocused follows selectedForcedColors. One comment says why the order matters. Nothing else changes.

Evidence

  • Reproduction before the change: Lab/Comments panel story in real Chromium, with the selected thread's toggle focused and no pointer input, so :focus-visible applies. The surface's computed outline is none, in light and dark.
  • Result after the change: solid 2px with the focus color, in light and dark.
  • Representative unchanged path: forced colors, selected but unfocused: the selection outline is the same before and after.
  • Regression test: CommentThread.test.tsx checks the focus-ring classes on [data-thread-surface] for a selected and a highlighted thread. It fails without the fix.
Before After
Selected thread focused, before Selected thread focused, after
Dark, before Dark, after
Forced colors, selected (unchanged) Forced colors, selected and focused (after)
Forced colors, selected Forced colors, selected and focused

Branded Chrome stills at this head

Google Chrome 158.0.8127.37 on macOS, in a one-off public Actions run. It built Storybook at this head (adfdc1f6) and at its merge base with main (4700add1), each with the same throwaway story: a margin thread with one reply, rendered selected or highlighted by its host. The run pressed Tab until the thread's toggle took keyboard focus. It used DPR 2 and reduced motion. The recorded outline on the focused thread is 3px none on main and 2px solid here.

Main (4700add1) This head
Selected, focused, light no ring focus ring
Selected, focused, dark no ring focus ring
Highlighted, focused, light no ring focus ring
Highlighted, focused, dark no ring focus ring

Scope

Components: Comments, CommentThread

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

  • On fix(Comments): a selected or highlighted thread shows its focus ring #13736: vitest run packages/lab/src/Comments passed, and the new cases fail without the fix. pnpm review:pre, prettier and eslint were clean, and real Chromium ran on static Storybook builds (light, dark, forced colors).
  • At this head (a clean cherry-pick onto current main), rerun on Linux:
    • install, build, tsc (core, lab), prettier, eslint and check:changesets all pass;
    • Lab Comments 96/96, twice.
  • Real Chromium 155, main against this head, on the Lab/Comments panel story:
    • selected and highlighted threads, light and dark: no ring on main (3px none); a 2px solid ring at offset 3px here;
    • forced colors, focused: main keeps the selection outline, and here the focus ring shows;
    • a plain thread is identical on both.

Overlap checked: #14155, #13741, #13740, #13738, #13737, #13736, #13739, #13735 (separate: #13736 is the original by @ernestt, which this team pull request replaces with the same commit on current main; #14155 replaces #13737; #13738, #13739, #13740, #13741 and #13735 are ernestt's other Comments pull requests, each its own change; whichever lands second merges main)

A thread's hidden toggle shows keyboard focus through a focus ring on the
thread's surface. On a selected or host-highlighted thread, the
forced-colors selection outline came after the ring in the style list and
unset its outline outside forced colors, so a keyboard user on the thread
they work in saw no focus. The ring now comes last. Forced colors keep the
selection outline on an unfocused thread.

Cherry-picked from #13736 (by @ernestt).

Co-authored-by: Ernest Tien <ernesttien@meta.com>
@vercel

vercel Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Dec 2, 2026 8:22pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Dec 1, 2026
@astracat-bot

astracat-bot Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🔄 In progress (for maintainers only) Dec 2, 2026, 8:23 PM UTC

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · adfdc1f

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
lab/CommentComposer 192.3 kB (0) · 1.9 kB CSS (0) — — · — · —
lab/Comments 392.3 kB (0) · 2.5 kB CSS (0) — — · ✓ · —
lab/CommentThread 385.4 kB (0) · 2.4 kB CSS (0) — — · — · —

Package size: no published package changed; no new dependencies.

Not run on this PR: add ci:run-visual for Visual, ci:run-rtl for RTL.


Generated by PR Enrichment workflow | View full report

@cixzhang

cixzhang commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec adfdc1f

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested for one sentence in the description; the code change itself looks right.

  • The Testing section says this branch is the validated work rebased onto an earlier main commit, but its only parent is the main commit it was opened on, 255 commits later (including #14106, which edits CommentActions.tsx and Comments.test.tsx), so please say which base the reported Vitest and Chromium results came from, or re-run them on this base.

From reading the code, moving surfaceFocused after selectedForcedColors restores the ring on selected and highlighted threads for both thread surfaces, and the new test pins it for the Card surface. CI has not run on this draft head yet.

Claims and files checked

Review mode: same-head; reason: none

  • Claim: a selected or highlighted thread now shows its focus ring. Verified (CommentRow.tsx:242-246; the Card and Section surfaces apply the list last, :256, :276; CommentThread.test.tsx:215-250 holds both cases for the Card surface).
  • Claim: the selection style came after the ring, and outside forced colors its outline removed the ring. Verified (the base style order; the style's null outline defaults at CommentRow.tsx:162-176).
  • Claim: unselected threads already showed the ring. Verified (the base style list).
  • Claim: forced colors keep the selection outline on an unfocused thread and draw the ring on a focused one. Verified from the style list; the rendering is reported.
  • Claim: the Comments docs promise the ring on the whole surface while the toggle has focus. Verified (Comments.doc.mjs:143).
  • Claim: the interaction-modality record has keyboard focus use the shared focus-visible treatment. Verified as a paraphrase of its system model.
  • Claim: an audit rubric item lists this defect, confirmed on main in Chromium. Reported.
  • Claim: only the style order and one comment change in the component. Verified (CommentRow.tsx +3/-1; the only other file is the test).
  • Claim: before and after Chromium results and screenshots in light, dark and forced colors. Reported.
  • Claim: the regression test checks the ring classes for a selected and a highlighted thread. Verified (CommentThread.test.tsx:215-250); that it fails without the fix is reported and traced against the base.
  • Claim: Vitest, the review checklist, Prettier and ESLint are clean. Reported; CI has not run on this head.
  • Claim: Chromium runs on static Storybook builds of main and this branch. Reported.
  • Claim: validated on an earlier main commit. Reported.
  • Claim: this branch is that work rebased onto an earlier main commit. False: its only parent is the base it was opened on, 255 commits later.
  • Claim: cherry-picked from #13736 by its author with co-author credit, as the same change. Verified (commit trailer; every patch line of #13736 is in this diff).
  • Claim: this pull request carries the fix onto current main. Verified as of opening: the head sits on the main commit it was opened on; main has since gained one commit that touches no Comments file.
  • Claim: #14155 replaces #13737. Verified (the same nine files with the same line counts).
  • Claim: the other listed pull requests are separate changes. Verified (none edits the thread surface's style list).
  • Claim: the scope checklist (one defect, no tag-alongs, no hidden API or visual direction, no internal context). Verified.
  • File packages/lab/src/Comments/CommentRow.tsx: clear.
  • File packages/lab/src/Comments/CommentThread.test.tsx: clear.

Automated review (maintainer link)

@cixzhang

cixzhang commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

🤖 (Posted by Cindy's agent.)

Thanks. The Testing section no longer says the branch was rebased. It now names what was checked on the original pull request, and the checks rerun at this head on current main. Only the description changed; the head is unchanged.

@cixzhang cixzhang added the ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) label Dec 1, 2026

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Moving the focus-ring style after the forced-colors selection style restores the ring on selected and highlighted threads, CI's unit tests at this head pass both new cases, and a Chromium check here reproduced the missing ring on main and the 2px ring with this change.

Claims and files checked

Review mode: same-head; reason: none

  • Rules changed since the last review: none.
  • Title: a selected or highlighted thread shows its focus ring. Verified (CommentRow.tsx:242-246; CI's test-ui passes both cases in CommentThread.test.tsx:215-250; reproduced locally on the OpenThread story: outline-style: none on the base, a 2px solid ring at offset 3px here, in light and dark).
  • Cherry-picked from #13736, with co-author credit for its author. Verified (the commit's Co-authored-by trailer; #13736's diff is byte-identical to this one).
  • This pull request carries the fix onto current main. Verified as of opening: the head's only parent was the main tip then; main has since gained 12 commits that touch no Comments file, Card, Section or focus token, and the head still merges cleanly.
  • On the base, keyboard focus on a selected or highlighted thread showed no ring, while unselected threads showed it. Verified (base style order; reproduced locally for the selected state).
  • The hidden toggle draws its ring on the thread surface. Verified (CommentRow.tsx:226-246).
  • The selection style came after the ring and, outside forced colors, left the outline at none. Verified (the null defaults at CommentRow.tsx:162-176; the base order; the local probe).
  • Enter or Space on the toggle opens and closes the thread. Verified (a native button, CommentRow.tsx:228-236; the existing keyboard test at CommentThread.test.tsx:189-213).
  • The ring now comes last; forced colors keep the selection outline on an unfocused thread and draw the ring on a focused one. Verified (the style list; reproduced locally in forced colors: the unfocused frame is pixel-identical, the focused one shows the ring).
  • The Comments docs promise the ring on the whole surface while the toggle has focus. Verified (Comments.doc.mjs:143).
  • The interaction-modality record has keyboard focus use the shared focus-visible treatment. Verified as a paraphrase of its system model.
  • An audit rubric item lists this defect, confirmed on main in Chromium. Reported.
  • Only the style order and one comment change in the component. Verified (CommentRow.tsx +3/-1; the only other file is the test).
  • Before and after Chromium results and screenshots in light, dark and forced colors. Reported, and consistent with the local run for the selected state.
  • The regression test checks the ring classes for a selected and a highlighted thread and fails without the fix. Verified that it checks both and passes in CI's test-ui at this head; the red run is reported and traced against the base.
  • The scope checklist: one defect, no tag-alongs, no hidden API or visual direction, no internal context. Verified.
  • On #13736, the Comments tests, pre-review checks, Prettier, ESLint and Chromium runs were clean. Reported.
  • At this head, install, build, typecheck, Prettier, ESLint and the changeset check pass, and the Comments tests pass 96 of 96. Reported; CI at this head passes its typecheck, lint and build jobs and runs all 96 Comments cases green.
  • In Chromium on the Comments Panel story, main shows no ring and this head a 2px solid ring at offset 3px on selected and highlighted threads, the ring shows in forced colors when focused, and a plain thread is unchanged. Reported; the selected and forced-colors states match the local run, and the committed stories render no highlighted thread, so that state needed a fixture the description does not name.
  • The listed pull requests are separate changes, #14155 replaces #13737, and the other five are the original author's own Comments pull requests. Verified (#14155 and #13737 change the same nine files; each of the others has its own title and files).
  • File packages/lab/src/Comments/CommentRow.tsx: clear.
  • File packages/lab/src/Comments/CommentThread.test.tsx: clear.

Automated review (maintainer link)

@cixzhang
cixzhang marked this pull request as ready for review December 1, 2026 19:48

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested. Moving the focus-ring style after the forced-colors selection style restores the ring on focused selected and highlighted threads (the new tests pass here and in CI, and a Chromium check here shows the ring), but one description claim does not hold.

  • Miss: after a thread's toggle is removed while it has focus (the host sets isSubmitting and then clears it), a selected or highlighted thread keeps the focus ring with focus on the page body and, in forced colors, shows it in place of the selection outline, so "Forced colors still draw the selection outline on an unfocused selected thread" is false until isFocused is cleared when the toggle detaches (for example in its ref callback) and a test covers that round trip.

The inline comment on CommentRow.tsx has the reproduction and a suggested fix.

Claims and files checked

Review mode: same-head; reason: none

  • Rules changed since the last review (3): "Claim bounding in one round": finding (the forced-colors sentence, bounded in Problem and solution fit and in Evidence). "Read the bound a claim already carries": checked: the sentence's own bound, an unfocused selected thread, excludes nothing, so only the removed-toggle case is listed. "For a claim about focus, events or DOM placement": a toggle removed while focused falsifies it; a click that leaves the toggle unfocused, a non-HTML control, an iframe or Picture-in-Picture window, a shadow root, a disabled or hidden toggle, a covering surface and a caller-supplied focus target do not apply, and Comments and CommentThread on both surfaces share the same code.
  • Title (live): "fix(Comments): a selected or highlighted thread shows its focus ring". Verified (CommentRow.tsx:242-246; the two new cases in CommentThread.test.tsx:215-250 pass here and in CI's test-ui; in Chromium here a focused selected thread goes from no outline to a 2px solid ring at offset 3px).
  • Cherry-picked from #13736, with co-author credit for its author. Verified (the commit's Co-authored-by trailer; every added line of #13736 is in this diff).
  • This pull request carries the fix onto current main. Verified (the head's only parent is the base; main has since gained commits that touch no Comments file, Card, Section or focus token, and the head still merges cleanly).
  • On the base, keyboard focus on a selected or highlighted thread showed no ring while unselected threads showed it. Verified (base style order; reproduced here on the base for both states).
  • The hidden toggle draws its ring on the thread surface. Verified (CommentRow.tsx:226-246).
  • The selection style came after the ring and, outside forced colors, set the outline to none. Verified (the null defaults at CommentRow.tsx:162-176; the base probe here).
  • Focus visibility fails on the open thread, and Enter or Space on the toggle opens and closes it. Verified (a native button at CommentRow.tsx:228-236; the keyboard test at CommentThread.test.tsx:189-213 passes here).
  • The ring now comes last. Verified (CommentRow.tsx:242-246).
  • Forced colors still draw the selection outline on an unfocused selected thread, and the ring on a focused one. False for an unfocused selected or highlighted thread whose toggle was removed while focused (see the finding); the focused half is verified.
  • The Comments docs promise the ring on the whole surface while the toggle has focus. Verified (Comments.doc.mjs:143).
  • Keyboard focus uses the shared focus-visible treatment under the interaction-modality record. Verified as a paraphrase of the record's system model; the record applies to Core, so it is context for this Lab change.
  • An audit rubric item lists this defect, confirmed on main in Chromium. Reported.
  • Only the style order and one comment change in the component. Verified (CommentRow.tsx +3/-1; the only other file is the test).
  • Before and after Chromium results in light and dark: no outline on the base, a 2px solid ring on the head. Reported; consistent with the runs here.
  • The unchanged forced-colors path for a selected, unfocused thread. Reported for a thread never focused; the same bound as the forced-colors claim applies.
  • The regression test checks the ring classes for a selected and a highlighted thread and fails without the fix. Verified (it checks both and passes here; the same class check finds no ring on the base here).
  • Chrome 158 stills from a public Actions run at this head and at its merge base with main, with a throwaway story: 3px none on main, 2px solid here. Reported; the merge base is correct and the values match the runs here.
  • The scope checklist: one defect, no tag-alongs, no hidden API or visual direction, no internal context. Verified (no API, default or interaction-model change and no internal context; the stray ring is the finding above, not a hidden direction).
  • On #13736, the Comments tests, pre-review checks, Prettier, ESLint and Chromium runs were clean. Reported.
  • At this head, install, build, typecheck, Prettier, ESLint and the changeset check pass, and the Comments tests pass 96 of 96. Reported; CI at this head passes its typecheck, lint, build and test-ui jobs.
  • In Chromium 155, main shows no ring and this head a 2px solid ring at offset 3px on selected and highlighted threads, the ring shows in forced colors when focused, and a plain thread is unchanged. Reported; consistent with the runs here.
  • The listed pull requests are separate changes, #14155 replaces #13737, and the others are the original author's own Comments pull requests. Verified (#14155 and #13737 change the same nine files; none of the others edits the thread surface's style list).
  • File packages/lab/src/Comments/CommentRow.tsx: finding (line 245 with the focus state at lines 215 and 234-235).
  • File packages/lab/src/Comments/CommentThread.test.tsx: clear.

Automated review (maintainer link)

isSelectable && styles.surface,
isSelectable && isFocused && styles.surfaceFocused,
isFilled && styles.selectedForcedColors,
isSelectable && isFocused && styles.surfaceFocused,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Miss: isFocused only changes in the toggle's onFocus and onBlur (lines 234-235), and React runs no onBlur when it removes the focused toggle, which happens while the thread cannot be selected (for example while the host's isSubmitting is true). With this style now last, a selected or highlighted thread keeps the ring after the toggle comes back, though focus is on the page body; in forced colors the ring also replaces the selection outline. Reproduced here in Chromium 158: Tab to a selected thread's toggle, set isSubmitting to true and then false, and the surface still computes a 2px solid outline at offset 3px with document.activeElement on the body (the base keeps no outline there, and the inset Highlight outline in forced colors).

Clearing the state when the toggle detaches fixes it, and a test for that round trip would pin it:

const setControl = useCallback((node: HTMLButtonElement | null) => {
  controlRef.current = node;
  // React runs no onBlur for a focused node it removes.
  if (node == null) {
    setIsFocused(false);
  }
}, []);

@cixzhang

cixzhang commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 4aa6bbc

This branch was successfully deployed

1 active deployment
Preview — 4aa6bbc3 Deployed Dec 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant